package com.java2018.springmvc.book.converter;

import com.java2018.springmvc.book.model.Book;
import com.java2018.springmvc.user.model.User;
import org.springframework.core.convert.converter.Converter;

import java.math.BigDecimal;
import java.util.Arrays;


public class BookConverter implements Converter<String,Book>{

    @Override
    public Book convert(String source) {

        System.out.println("book 处理。。。。");
        if(source!=null){
            System.out.println(source);
            String [] arr = source.split("-");
            if(arr!=null && arr.length==3){
                Book book = new Book();
                book.setName(arr[0]);
                book.setPrice(new BigDecimal(arr[1]));
                book.setId(arr[2]);
                return book;
            }
        }
        return null;
    }
}
